﻿Ext.namespace('EHSubmit.Analysis');
Ext.namespace('EHSubmit.Analysis.List');
Ext.namespace('EHSubmit.Analysis.ScoreList');
//////////////////////////////////////////////////////////////////////
EHSubmit.Analysis.ScoreList.courseId = '';   // 点击显示学生平均成绩表时传递的参数 courseId
// 某课程所有作业的 列模式
EHSubmit.Analysis.ScoreList.ColumnModel = new Ext.grid.ColumnModel([
    { header: '学生ID', width: 150, sortable: true, hidden: false, dataIndex: 'StudentID' },
    { header: '学生姓名', width: 150, sortable: true, hidden: false, dataIndex: 'StudentName' },
    { header: '该课程平作业均分', width: 150, sortable: true, hidden:false, dataIndex: 'Average' }
]);
// 某课程所有作业的 数据源
EHSubmit.Analysis.ScoreList.DataStore = new Ext.data.Store({
    baseParams: { Op: 'student', courseId: '' },      // 需要传递操作参数  sid学生的ID
    proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'AnalysisHandler.ashx' }),  //后台具体处理

    reader: new Ext.data.JsonReader({
            totalProperty: 'count',    //总记录个数
            root: 'data',
            id: 'StudentID'
        },
        [   // 数据模型
            { name: 'StudentID' },
            { name: 'StudentName' },
            { name: 'Average' }
    ]),
    listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
});



EHSubmit.Analysis.ScoreList.GridPanel = {
    xtype: 'grid',
    //title: '课程平均分',
    id: 'Analysis_StudentAverageGrid',
    frame: false,
    border: false,
    //autoExpandColumn: 3, 
    //autoHeight: true,       // 自动调整高度
	width:450,
    height: 400,
    loadMask: true,           // 加载数据时遮住
    ds: EHSubmit.Analysis.ScoreList.DataStore,
    cm: EHSubmit.Analysis.ScoreList.ColumnModel
    
    /*listeners: {
        render: function(thisGrid) {
            //----------请求单页数据-----------------
			var store = thisGrid.getStore();
			store.setBaseParam('courseId',EHSubmit.Analysis.ScoreList.courseId);
            store.load();
        },
        //        render: function(g) {
        //            g.getSelectionModel().selectRow(0);
        //        },
        delay: 10 // Allow rows to be rendered.
    }*/

};
//***************** 弹出窗，某课程学生平均分列表 ************************

EHSubmit.Analysis.ScoreList.WinConfig ={
	id: 'detailsWindow',
	xtype: 'window',
	width: 450,
	height: 450,
	//plain: true,
	border: true,
	layout: 'fit',
	modal: true,
	title: '学生平均成绩列表',
	frame: true,
	items:EHSubmit.Analysis.ScoreList.GridPanel,
	buttons:[
		{
			text:'确定',
			handler: function(){
				EHSubmit.closeWin(EHSubmit.Analysis.ScoreList.WinConfig);
			}
		}		 
	],
	listeners:{
		activate: function(){
			var store = Ext.getCmp('Analysis_StudentAverageGrid').getStore();
			store.setBaseParam('courseId',EHSubmit.Analysis.ScoreList.courseId);
            store.load();
		}	
	}
	
}



//////////////////////////////////////////////////////////////////////
//********************************************************************
// 某课程所有作业的 列模式
EHSubmit.Analysis.List.ColumnModel = new Ext.grid.ColumnModel([
    { header: '作业ID', width: 40, sortable: true, hidden: true, dataIndex: 'ID' },
    { header: '作业名', width: 100, sortable: true, hidden: false, dataIndex: 'Title' },
    { header: '布置时间', width: 80, sortable: true, renderer: Ext.util.Format.dateRenderer('Y年m月d日'), dataIndex: 'PublishTime' }
/*    { header: '最后期限', width: 80, sortable: true, renderer: Ext.util.Format.dateRenderer('Y年m月d日'), dataIndex: 'DeadLine' },
    { header: '附件', width: 20, sortable: false, renderer: EHSubmit.Format.goalAttachRenderer, dataIndex: 'AttachPath' },
    { header: '说明', sortable: false, dataIndex: 'Description' }*/
]);

// 某课程所有作业的 数据源
EHSubmit.Analysis.List.DataStore = new Ext.data.Store({
    baseParams: { Op: 'List_Goals', courseID: '' },      // 需要传递操作参数  sid学生的ID
    proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'GoalHandler.ashx' }),  //后台具体处理

    reader: new Ext.data.JsonReader({
            totalProperty: 'count',    //总记录个数
            root: 'goals',
            id: 'ID'
        },
        [   // 数据模型
            { name: 'ID' },
            { name: 'Title' },
            { name: 'PublishTime' }
/*            { name: 'DeadLine' },
            { name: 'AttachPath' },
            { name: 'Description' }*/
    ]),
    listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
});

//-------容器--------------
EHSubmit.Analysis.Tab = {
    id: 'analysisForm',
    layout: 'column',
    frame: false,
    closable: true,
    title: '成绩分析',
    bodyStyle: 'padding:5px;',
    border: false,
    defaults: { bodyStyle: 'padding:5px;', border: false },
    items: [{
        columnWidth: 0.3,
        layout: 'fit',
        items: {
            title:'选择课程',
			frame:true,
			height:400,
			layout:'form',
			items:[
			{
				id: 'Analysis_CursesCombo',
				xtype:'combo',
				editable: false,
				//width: 200,
				emptyText: '请选择...',
				fieldLabel:'请选择一门课程',
				mode: 'remote',
				triggerAction: 'all',
				selectOnFocus: true,
				valueField: 'courseID',
				displayField: 'courseName',
	
				/*  
				* 关键点(网上资料)
				* 1. x-menu使combo在选择的时候不会隐藏掉menu,看Ext.menu.MenuMgr.onMouseDown源码即知  
				* 2. x-menu里面的"z-index: 15000;",因为menu里面的layer的z-index是15000,则这里大于15000(需要限制覆盖原来的文档元素element.style)即可..   
				* 如果实际用x-menu，其他有应用x-menu的会受到干扰，设置还需考虑适当的值
				*/
				listClass: 'x-menu',
				store: new Ext.data.JsonStore({
					storeId: 'courseStore',
					//autoLoad: true,
					baseParams: { Op: 'List_Course' },     //根据教师id获取其教的课程
					proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'CourseHandler.ashx' }),  //后台具体处理
	
					root: 'courses',
					fields: [
						{ name: 'courseID', mapping: 'Id' },
						{ name: 'courseName', mapping: 'Name' }
					]
				}),
	
				listeners: {
					select: function(combo, record, index) {
						
						var store = Ext.getCmp('analysis_course_chart').store;
						var courseId = record.data.courseID;
					    store.setBaseParam('courseID', courseId);
					    store.load();
						
						//显示图表面板
						//tp_chart.show();
						Ext.getCmp('analysis_GoalChartPanel').hide();
						Ext.getCmp('analysis_CourseChartPanel').show();
						
						// 保存选择的courseId值，显示成绩表时调用
						EHSubmit.Analysis.ScoreList.courseId = courseId;
						
//						//根据班级课程id和教师id获取发布的作业通知
//						EHSubmit.Work.List.courseID = record.data.courseID;
//						Ext.getCmp('goalsCombo').clearValue();
//						Ext.getCmp('goalsCombo').enable();
						var gridStore = Ext.getCmp('Analysis_WorkListGrid').getStore();
						gridStore.setBaseParam('courseID', record.data.courseID);     // 传递courseID
						gridStore.load();
					}
				}
			},
			{   
				//****************************显示已布置作业列表*****************
				xtype:'grid',
				id:'Analysis_WorkListGrid',
				loadMask: true,          // 加载数据时遮住
				frame: true,
				height: 300,
				cm: EHSubmit.Analysis.List.ColumnModel,
    			ds: EHSubmit.Analysis.List.DataStore,
				sm: new Ext.grid.RowSelectionModel({
					singleSelect: true
				}),
				listeners:{
					cellclick: function(thisGrid, rowIndex, columnIndex, e){
						// 切换图表示图
						Ext.getCmp('analysis_CourseChartPanel').hide();
						
						Ext.getCmp('analysis_GoalChartPanel').show();
											
						var store = Ext.getCmp('analysis_goal_chart').store;
						var goalId = thisGrid.getStore().getAt(rowIndex).data.ID;
						store.setBaseParam('goalId',goalId);
						store.load();
						Ext.getCmp('analysis_goal_chart').show();
					},
					delay: 10   // allow rows to be rendered
				}
    			
			}   //end of grid
			
			]
        }
    }, {   //end of column 1
        columnWidth: 0.7,
        layout: 'fit',
        items: 
		[{
			id:'analysis_CourseChartPanel',
		    title:'课程统计',
			frame:true,
			//height:,
			autoHeight:true,
			items:[
				{
					xtype:'columnchart',
					url: EHSubmit.extRoot + 'resources/charts.swf',
					id:'analysis_course_chart',
					plugins: new Ext.ux.plugin.VisibilityMode(),
					height:400,
					xField: 'GoalName',
					yAxis: new Ext.chart.NumericAxis({
						displayName: '分数',
						labelRenderer : Ext.util.Format.numberRenderer('0,0')
					}),
					store: new Ext.data.JsonStore({
						//autoLoad: true,
						baseParams: { Op: 'course' },     //根据教师id获取其教的课程
						proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'AnalysisHandler.ashx' }),  //后台具体处理
						root: 'data',
						fields: [
							{ name: 'GoalID', mapping: 'GoalID' },
							{ name: 'GoalName', mapping: 'GoalName' },
							{ name: 'Max', mapping: 'Max' },
							{ name: 'Min', mapping: 'Min' },
							{ name: 'Average', mapping: 'Average' }
						]
					}),
					series: [{
						type: 'line',
						displayName: '最高分',
						yField: 'Max',
						style: {
							color:0x00FF00
						}
					},{
						type:'line',
						displayName: '平均分',
						yField: 'Average',
						style: {
							color: 0x15428B
						}
					},{
						type:'line',
						displayName: '最低分',
						yField: 'Min',
						style: {
							color: 0xFF0000
						}
					}]   
				}  //end of chart 1
			],
			buttons:[{
				text:'学生平均成绩表',
				handler: function(){
					EHSubmit.showWin(EHSubmit.Analysis.ScoreList.WinConfig);
				}
			}]
		},   //end of line chart panel
		{
			id:'analysis_GoalChartPanel',
			hidden:true,
			title:'作业统计',
			frame:true,
			height:400,
			items:[
				{
					id:'analysis_goal_chart',
					xtype:'piechart',
					plugins: new Ext.ux.plugin.VisibilityMode(),
					height: 360,
					url: EHSubmit.extRoot + 'resources/charts.swf',
					dataField: 'Total',
					categoryField: 'Category',
					store:new Ext.data.JsonStore({
						//autoLoad: true,
						baseParams: { Op: 'goal',goalId:'' },     //根据教师id获取其教的课程
						proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'AnalysisHandler.ashx' }),  //后台具体处理
						root: 'data',
						fields: [
							{ name: 'Category', mapping: 'Category' },
							{ name: 'Total', mapping: 'Total' }
						]
					}),
					extraStyle:
					{
						legend:
						{
							display: 'bottom',
							padding: 5,
							font:
							{
								family: 'Tahoma',
								size: 13
							}
						}
					}
				}
			]//end of items
			
		}  // end of pie chart panel
		]
    },   //end of column2 
	
	]
};
